package otherCode;

public class Singleton {
    private static volatile Singleton instance;

    public Singleton() {
        System.out.println("init");
    }

    public static Singleton get() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}

 class Singleton2 {
    private Singleton2(){
    }
    public static Singleton getSingleton(){
        return Inner.instance;
    }
    private static class Inner {
        private static final Singleton instance = new Singleton();
    }
}



